<?php
function get_document_head(){

	$title = 'Diplomacy';
	$css_file = 'view/templates/css/style.css';
	$java_script = 'js/scripts.js';
	$jquery = 'js/jquery-1.4.3.js';

    $output='';

    $output = <<<OUT
	<!DOCTYPE html>
	<html>
		<head>
			<title>Diplomacy</title>
			<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
			<script src="js/jquery-1.4.3.js" type="text/javascript"></script>
			<script src="js/jquery-ui-1.8.6.custom.min.js" type="text/javascript"></script>

			<link rel="stylesheet" href="view/templates/style/reset.css" type="text/css" charset="utf-8" />
			<link rel="stylesheet" href="view/templates/style/general.css" type="text/css" charset="utf-8" />
			<link rel="stylesheet" href="view/templates/style/style.css" type="text/css" charset="utf-8" />
			<script src="js/drawmap.js" type="text/javascript" charset="utf-8"></script>
			<script src="js/scripts.js" type="text/javascript" charset="utf-8"></script>
			<script src="js/addunits.js" type="text/javascript" charset="utf-8"></script>
			<script src="js/newmapanim.js" type="text/javascript" charset="utf-8"></script>
			<script src="js/addneighbors.js" type="text/javascript" charset="utf-8"></script>
	</head>
		<body>
			<div id="container">
OUT;
			//<script src="js/gamedragdrop.js" type="text/javascript" charset="utf-8"></script>
			//<script src="js/date-picker.js" type="text/javascript" charset="utf-8"></script>

	return $output;

}
function get_themes(){
    $output='';
    $output = <<<OUT
			<audio loop="loop" autoplay="autoplay">
			  <source src="diplomacy_themes/shire.ogg" type="audio/ogg" />
			  <source src="diplomacy_themes/shire.mp3" type="audio/mpeg" />
			</audio>
OUT;

	return $output;
}

function get_header(){
    $output='';
    $output = <<<OUT

			<div id="header">
				<div class="wrapper">
					<h1 id="diplomacy" class="whole"><a href="?p=startpage">diplomacy</a></h1>
				</div>
			</div>
OUT;

	return $output;
}
function get_wrapper(){
    return '<div id="main" class="wrapper">';

}

function get_leftsidebar(){
return '<div id="leftSidebar" class="threeSixteenths">';
}

function get_menu(){
    $output = '';

    $output = <<<OUT
					<div id="menu">
						<ul>
							<li class="firstListChild"><a href="?p=startpage">Home</a></li>
							<li><a href="?p=games">Games</a></li>
							<li><a href="?p=creategame">Create Game</a></li>
							<li class="lastListChild"><a href="?p=newmap">Create New Map</a></li>
							<!-- <li class="lastListChild"><a href="?p=chat">Chat Room</a></li> -->
						</ul>
					</div> <!-- Closing menu -->
OUT;

	return $output;
}
							//<li><a href="?p=game">Demo</a></li>

function get_leftsidebar_end(){
return '</div><!-- Closing Sidebar -->';
}

function get_startpage($user_id){
	$user_info = select_from_db(array('*'),array('users'),array("id=$user_id"));
	$user_alias = $user_info[0]['alias'];
	$user_avatar = $user_info[0]['avatar'];
	$user_firstname = $user_info[0]['first_name'];
	$user_lastname = $user_info[0]['last_name'];
	$user_country = $user_info[0]['country'];
	$user_city = $user_info[0]['city'];
	$user_birthyear = date('Y')-$user_info[0]['birth_date'];
	$user_skype = $user_info[0]['skype'];
	$user_in_game = select_from_db(array('games.name, games.id'),array('games','users__got__games'),array("users__got__games.user_id=$user_id", 'users__got__games.game_id=games.id'));
	$games_list = ""; 
	foreach($user_in_game as $game_name){
				$games_list .= "<li><a href='index.php?p=game_lobby&g=". $game_name['id'] ."'>". $game_name['name'] . "</a></li>" . ", ";
			}
	
	
	$output = '';

    $output = <<<OUT
				<div id="playerInfoBox" class="nineSixteenths">
					<div class="left avatarImage">
						<a href="$user_avatar"><img src="$user_avatar" alt="Avatar"/></a>
						<p><a href="?p=uploadavatar">upload avatar</a></p>
					</div>
					<div class="left info">
						<p>alias: <span class="info-val">$user_alias</span> </p>
						<p>name: <span class="info-val">$user_firstname, $user_lastname</span></p>
						<p>age: <span class="info-val">$user_birthyear</span></p>					
						<p>skype: <span class="info-val">$user_skype</span></p>
						<p>location: <span class="info-val">$user_city, $user_country</span></p>
						<ul id="games-list">Games in: $games_list</ul>
					</div>
				</div>
OUT;

return $output;
}

function get_uploadavatar($user_id,$user_alias,$user_avatar){

	
	$output = '';

    $output = <<<OUT
				<div id="playerInfoBox" class="nineSixteenths">
					<div class="left avatarImage">
						<img src="$user_avatar" alt="Avatar" />
					</div>
				    <div id="fileUpload">
						<form action="controller/form_handler.php" method="post" enctype="multipart/form-data">
							<label for="file">Avatar:</label>
							<input type="file" name="file" id="file" />
				            <input type="hidden" value="file_upload" name="_get_function" id="_get_function">
							
							<p>Max size 2mb, jpg, gif and png alowed.</p>
							<input type="submit" name="submit" value="Upload" />
						</form>
					</div>
				</div>
OUT;

return $output;
}

function get_game($game_id,$chat_room_id,$user_id){


//	$userarray = select_from_db(array('users.id','users.alias','users__got__games.land'),array('users','users__got__games'),array('users__got__games.game_id = 5','users__got__games.user_id = users.id'));
//	$statstring = "";
//	foreach($userarray as $userinfo){
//		$land = $userinfo['land'];
//		$alias = $userinfo['alias'];
//		$user_id = $userinfo['id'];
//		$statstring .= "<li id='$land-stats'> <span class='countryStatsItem'>(5/1)</span><div class='gameChatUserListContainer'><form id='user_in_chat' method='post' class='gameChatUserList'><input type='hidden' value='$user_id' name='user_id'><input type='submit' value='$alias'' class='ooo' name='create_private_chat'></form></div></li>
//	
//		";
//	}

	include('controller/fetchmapsinfo.php');
	$output = '';

	$output = <<<OUT
				<div id="countryStats" class="whole">
					<div class="gameChatUserListContainer">
						<ul>
							$statstring
						</ul>
					</div>
				</div>
				<div id="chat_room_id_$chat_room_id" class="chatRoomInGame">
					<div class="dragableMainchat"></div>
					<div id="chat_room_id_$chat_room_id" class="chat_message_container">
						<div class="chat_message_container">
							<dl>
							</dl>
						</div>
						<div class="chatFormContainer">
							<form action="" class="chatForm" method="post">
								<input type="text" id="message" name="message" />
								<div id="room_and_game_information">
									<input type="hidden" id="chat_room_id" name="chat_room_id" value="$chat_room_id" />
									<input type="hidden" id="user_id" name="user_id" value="$user_id" />
									<input type="hidden" id="game_id" name="game_id" value="$game_id" />
								</div>
								<input type="submit" id="send" value="skicka" style="visibility:hidden" />
							</form>
						</div>
					</div>
				</div>
OUT;

	return $output;
}
//				<div id="users_in_chat_$chat_room_id" class="chatRoomInGameUserlist">
//					<ul>
//					</ul>
//				</div>

function get_newmap(){
	$output = '';

	$output = <<<OUT
		<div id="options">
			<form id="finishmap" action="controller/drawmaps.php" method="post">
				<div class="left oneThird">
					<label for="mapname" class="fillform-1 fillformanim">Name of map:</label><br />
					<input type="text" name="mapname" id="mapname" class="fillform-1 fillformanim"/>
					<img src="images/ok-button.png" alt="ok" class="okButton okButton-1" />
					<br />
					<input type="submit" value="finish map" id="submitmap" class="formButton fillform-6 fillformanim"/>				
				</div>
				<div class="oneThird">
					<label for="province" class="fillform-2 fillformanim">Name a province:</label><br />
					<input type="text" name="province" id="province" class="fillform-2 fillformanim" />
					<img src="images/ok-button.png" alt="ok" class="okButton okButton-2" /><br />
					<input type="button" id="newprovince" value="save province" name="submitprovince" class="formButton fillform-4 fillformanim"/>
				</div>
				<div id="colorpick" class="oneThird">
					<label for="color" class="fillform-3 fillformanim">Chose color:</label>
					<br />
					<SELECT name="color" id="color" class="fillform-3 fillformanim">
						<option value="color" selected="selected">color</selected>
						<option value="brown">Brown</option>
						<option value="darkblue">Darkblue</option>
						<option value="lightblue">Lightblue</option>
						<option value="red">Red</option>
						<option value="black">Black</option>
						<option value="green" >Green</option>
						<option value="white">White</option>
						<option value="yellow">Yellow</option>
					</SELECT>
					<img src="images/ok-button.png" alt="ok" class="okButton okButton-3" />
					<br/>
					<input type="button" id="newflag" value="army position" class="formButton fillform-5 fillformanim" />
				</div>
			</form>
		</div>
		<img src="images/map.jpg" id="gamemap" class="formButton fillform-4 fillformanim">
		<canvas id="drawcanvas" width="960px" height="804px" ></canvas>
OUT;
	return $output;
}

function get_addunits($mapid){

	$output = '';

	$output = <<<OUT
		<form id="options" id="finishaddarmy" action="index.php?p=addneighbors&mapid=$mapid" method="post">
			<input type="button" value="Add army" id="addarmy"/>
			<br/>
			<input type="submit" value="Finish!" id="finishbutton"/>
			<input type="hidden" value="$mapid" id="mapname" name="mapname"/>
		</form>
		<img src="images/$mapid/mapfront.jpg" id="map"/>
OUT;
	return $output;
}


function get_userpage($user_alias,$user_avatar,$user_firstname,$user_lastname,$user_email,$user_country,$user_city,$user_birthyear,$user_skype,$games_list){

	
	$output = '';

    $output = <<<OUT
				<div id="playerInfoBox" class="nineSixteenths">
					<div class="left avatarImage">
						<img src="$user_avatar" alt="Gio" />
					</div>
					<div class="left info">
						<p>alias: <span class="info-val">$user_alias</span> </p>
						<p>name: <span class="info-val">$user_firstname, $user_lastname</span></p>
						<p>email: <span class="info-val"><a href="mailto:$user_email">$user_email</a></span></p>
						<p>age: <span class="info-val">$user_birthyear</span></p>					
						<p>skype: <span class="info-val">$user_skype</span></p>
						<p>location: <span class="info-val">$user_city, $user_country</span></p>
						<ul id="games-list">Games in: $games_list</ul>
					</div>
				</div>
OUT;

return $output;
}

function get_addneighbors($mapid){
	include('controller/addneighbors.php');

	$output = '';

	$output = <<<OUT
	
OUT;
	return $output;
}

function get_creategame(){ //I default_game_template ska det inte finnas n�gon lokik, den ska ligga i page.php.
	$options = "";
	//fetch all directories from images and put in array
	$dir = "images";
	$dirlist = array();
	$files = scandir($dir);
	foreach($files as $f){
		if(is_dir($dir.'/'.$f)){
			if($f !== "." && $f !== ".." && $f !== ".svn")
				$dirlist[] = $f;
		}
	}
	for($i=0;$i<count($dirlist);$i++){
		if($dirlist[$i]=='None')
			$options .= "<option value='$dirlist[$i]' selected='selected'>$dirlist[$i]</option>";
		else
			$options .= "<option value='$dirlist[$i]'>$dirlist[$i]</option>";
	}
	//echo $options;
	$output = '';

	$output = <<<OUT
				<div id="content">
					<h2 class="threeQuarters">Create new game</h2>
					<form action="controller/form_handler.php" method="post" id="create_game_form" class="left threeEights">
						<label for="name">name of game.</label><br />
						<input type="text" value="" name="name" id="mapname" />
						<br />
						<label for="start_time">Select start date.</label><br />
						<input type="text" name="start_time" value="" id="datepicker"/>
						<br/>

						<label for="start_date">Select start time.</label><br />
						<input type="text" name="start_date" value="00:00" id="timepicker"/>
						<br/>
						
						<label for="round_time">Round time.</label><br />
						<select name="round_time" id="round_time">
							<option value="10">10</option>
							<option value="15">15</option>
							<option value="20">20</option>
							<option value="25">25</option>
						</select><br />
						
						<label for="password">Password.</label><br />
						<input type="password" name="game_password"/>
						<input type="hidden" name="_get_function" value="create_game"/>
						<br/>
						
						<label for="country">Country.</label><br />
						<select id="country" name="country">
							<option value="russia">Russia</option>
							<option value="italy">Italy</option>
							<option value="germany">Germany</option>
							<option value="france">France</option>
							<option value="austria">Austria</option>
							<option value="england">England</option>
							<option value="turkey">Turkey</option>
						</select>
						<br/>
							
						<label for="map"> choose map.</label><br />
						<select name="map" id="changemap">
							$options
						</select><br />
						
						<input type="submit" name="submitNewGame" id="submitNewGame">
					</form>
					<div id="mapholder" class="right threeEights">
						<img src="images/none/mapfront.jpg" width="340px"/>
					</div>
    			</div>
OUT;
	return $output;
}
function get_main_chat($user_id,$chat_room_id,$game_id){
	$output = '';

    $output = <<<OUT
				<div id="content">
					<h2>Welcome captain</h2>
					<div id="chat_room_id_$chat_room_id" class="chat_room_fixed">
						<div class="nineSixteenths">
							<div class="fixed_chat_container">
								<div class="chat_message_container">
									<dl>
									</dl>
								</div>
								<div id="users_in_chat_$chat_room_id" class="users_in_chat">
									<ul>
									</ul>
								</div>
								<div id="message_container">
									<form action="" id="chat_form" method="post">
										<input type="text" id="message" name="message" />
										<div id="room_and_game_information">
											<input type="hidden" id="chat_room_id" name="chat_room_id" value="$chat_room_id" />
											<input type="hidden" id="user_id" name="user_id" value="$user_id" />
											<input type="hidden" id="game_id" name="game_id" value="$game_id" />
										</div>
										<input type="submit" id="send" value="skicka" style="visibility:hidden" />
									</form>
								</div>
							</div>
						</div>
					</div>
					<span id="create_room">skapa ett privat rum</span>
    			</div>
OUT;

return $output;
}

//function get_my_games_start(){
//	$output = '';
//
//    $output = <<<OUT
//				<div id="content" class="nineSixteenths">
//					<h2>My Games</h2>
//
//OUT;
//
//return $output;
//}


//function get_my_games_end(){
//	return "</p></div>";
//}
function get_games_start(){
	$output = '';

    $output = <<<OUT
				<div id="content" class="nineSixteenths">
					<h2>My Games</h2>
					<div class="myGameList">
OUT;

return $output;
}

function get_my_games_list($game_id,$game_name,$start_time,$round_time){
	$output = '';

    $output = <<<OUT
				<a href="?p=game_lobby&g=$game_id" class="paddl">$game_name</a> <span class="paddr right">starts: $start_time, round time:$round_time minutes</span><br />
OUT;

return $output;
}
function get_games_breake(){
return "</div><h2>Coming Games</h2></p>";
}
	
function get_coming_games_list($game_id,$game_name,$start_time,$round_time){
	$output = '';

    $output = <<<OUT
			<form action="" method="post" class="comingGameList" id="join_game_$game_id" />
				<input type="hidden" value="$game_id" name="game_id"/>
				<label for="join_game_$game_id" style="display:none;">$game_name</label>
				<input class="paddl comingGameListJoinButton" type="submit" value="$game_name" name="join_game_$game_id"/>
				<span class="paddr right">Starts: $start_time, Round time:$round_time min</span>
			</form>
OUT;

return $output;
}

function get_games_end() {
	return "</p></div>";
}

function get_game_lobby_start(){
	$output = '';

    $output = <<<OUT
				<div id="content">
					<h2 class="nineSixteenths">Game Lobby</h2>
					

OUT;

return $output;
}

function get_game_info($game_id,$game_name,$start_time,$round_time) {
	$output = '';

    $output = <<<OUT
	
				<!-- <div id="gameinfo">
					<h3>$game_name</h3><br />
					<h4>Starttid: $start_time Tid per omgång: $round_time</h4>
				</div> -->
OUT;

return $output;
}

function get_game_lobby_chat($game_id,$chat_room_id,$user_id) {
	$output = '';

    $output = <<<OUT

				<div id="chat_room_id_$chat_room_id" class="chat_room_fixed nineSixteenths">
					<div class="chat_message_container">
						<dl>
						</dl>
					</div>
					<div class="chat_form_container">
						<form action="" class="chat_form" method="post">
							<input type="text" id="message" name="message" />
							<div id="room_and_game_information">
								<input type="hidden" id="chat_room_id" name="chat_room_id" value="$chat_room_id" />
								<input type="hidden" id="user_id" name="user_id" value="$user_id" />
								<input type="hidden" id="game_id" name="game_id" value="$game_id" />
							</div>
							<input type="submit" id="send" value="skicka" style="visibility:hidden" />
						</form>
					</div>
				</div>
	
				<div id="users_in_chat_$chat_room_id" class="userslist right oneQuarter">
					<ul>
					</ul>
				</div>
				<div id="gotogame" class="right oneQuarter">
					<a href="?p=game&gameid=$game_id" id="gotogamelink">Start game</a>
				</div>
OUT;
return $output;
}

function get_game_lobby_end() {
	return "</div>";
}

function get_users_in_game($user_id,$alias) {
return "<!--<span><a href='$user_id'>$alias</a></span><br />-->";
}

function get_rightsidebar(){
return '<div id="rightSidebar" class="right oneQuarter">';
}

function get_userinfo($alias,$user_id,$visits,$last_visit){

	
    $output = '';

    $output = <<<OUT
					<div id="userInfoSidebar">
						<dl>
							<dt>User</dt>
								<dd>$alias - id: $user_id</dd>
							<dt>Earlier visits</dt>
								<dd>$visits st</dd>
							<dt>Latest visit</dt>
								<dd>$last_visit</dd>
						</dl>
						 <form id="logout" action="controller/form_handler.php" method="post">
			                <input type="submit" value="Logout" name="submit" id="submitLogout"/>
			                <input type="hidden" value="logout" name="_get_function" id="_get_function">
			            </form>
					</div> <!-- Closing userinfo -->
OUT;

	return $output;
}


function get_rightsidebar_end(){
return '</div><!-- Closing rightSidebar -->';
}


function get_wrapper_end(){
	return '</div><!-- Closing Wrapper -->';
}

function get_footer(){
	$output = '';

    $output = <<<OUT
			<div class="clearfooter"></div>
		</div><!-- Closing Container -->
		<div id="footer">
		</div>
OUT;

return $output;

}

function get_document_end(){

	$output='';

	$output = <<<OUT

		</body>
	</html>

OUT;

	return $output;

}